package org.dreamwork.jasmine2.restful;

/**
 * Created with IntelliJ IDEA.
 * User: seth.yang
 * Date: 14-11-17
 * Time: 下午5:38
 */
public class RestfulAPIException extends Exception {
    private int errorCode;
    private RestfulAPIErrorMessage em;

    public RestfulAPIException (int errorCode) {
        this.errorCode = errorCode;
    }

    public RestfulAPIException (String message, int errorCode) {
        super (message);
        this.errorCode = errorCode;
    }

    public RestfulAPIException (String message, Throwable cause, int errorCode) {
        super (message, cause);
        this.errorCode = errorCode;
    }

    public RestfulAPIException (Throwable cause, int errorCode) {
        super (cause);
        this.errorCode = errorCode;
    }

    public RestfulAPIException (RestfulAPIErrorMessage message) {
        this (message.getMessage (), message.getCode ());
        this.em = message;
    }

    public RestfulAPIException (RestfulAPIErrorMessage message, Throwable cause) {
        this (message.getMessage (), cause, message.getCode ());
        this.em = message;
    }

    public int getErrorCode () {
        return errorCode;
    }

    public RestfulAPIErrorMessage buildErrorMessage () {
        return em == null ? em = new RestfulAPIErrorMessage (getErrorCode (), getMessage ()) : em;
    }
}